<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\1\6 0006
 * Time: 10:54
 */
namespace app\api\model;
use think\Model;
class Version extends Model{

    /**
     * 获取更新状态
     * @author 王柯 <wangke.email@foxmail.com>
     * @return mixed
     */
    public function getIsUpdateAttr($value){
        $is_update = [
            null => null,
            0 => '不更新',
            1 => '需要更新',
            2 => '强制更新',
        ];
        return $is_update[$value];
    }

    /**
     * 检测更新
     * @param $app_type string app类型 *必传
     * @author 王柯 <wangke.email@foxmail.com>
     * @return mixed
     */
    public function check_update($app_type = '') {
        $data = [
            'app_type' => strtolower($app_type),
        ];

        $order = [
            'id' => 'desc',
        ];

        return $this->where($data)
            ->order($order)
            ->limit(1)
            ->find();
    }

}